package Acm;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Scanner;

public class AContrastValueOther {
    static final int maxn = 300010;
    static int n, m;
    static int[] a = new int[maxn];
    static int v;
    public static void solve(Scanner sc) {
        n = sc.nextInt();
        for (int i = 0; i < n; ++i) {
            a[i] = sc.nextInt();
        }
        int j = 1;
        for (int i = 1; i < n; ++i) {
            if (a[i] != a[i - 1]) {
                a[j++] = a[i];
            }
        }
        n = j;
        int ans = Math.min(2, n);
        for (int i = 1; i < n - 1; ++i) {
            if ((a[i] > a[i - 1] && a[i] > a[i + 1]) ||
                    (a[i] < a[i - 1] && a[i] < a[i + 1])) {
                ++ans;
            }
        }
        System.out.println(ans);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            solve(sc);
        }
        sc.close();
    }
}
